//
//  DDbaseNetWork+Login.m
//  hnGovernment
//
//  Created by 张辉男 on 17/3/7.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "DDbaseNetWork+Login.h"

@implementation DDbaseNetWork (Login)
- (NSNumber *)login:(NSString *)loginName passWord:(NSString *)passWord controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure{
    NSDictionary *params = @{
                             @"loginname":loginName,
                             @"password":passWord,
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/login" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}


- (NSNumber *)sendMSMcode:(NSString *)mobile controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"mobilephone":mobile,
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/regSendsmscode" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)checkSMScode:(NSString *)smsCode mobile:(NSString *)mobile controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"mobile":mobile,
                             @"captcha":smsCode
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/regCheckFirstHeNan" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)registerUseMobile:(NSString *)mobile password:(NSString *)password smsCode:(NSString *)smsCode controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"mobile":mobile,
                             @"captcha":smsCode,
                             @"passwd":password,
                             @"passwdConfirm":password
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/regCheckSecondHeNan" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)queryAllUseMsgUseToken:(NSString *)token controller:(NSObject *)controller success:(successBlock)success faliure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"token":token
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/getUser" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)saveUserInfoWithToken:(NSString *)token displayName:(NSString *)displayName passport:(NSString *)passport military:(NSString *)military receiverName:(NSString *)receiverName mobile:(NSString *)mobile province:(NSString *)province city:(NSString *)city district:(NSString *)district street:(NSString *)street details:(NSString *)details controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure{
    if (!passport) {
        passport = @"";
    }
    if (!displayName) {
        displayName = @"";
    }
    if (!military) {
        military = @"";
    }
    if (!receiverName) {
        receiverName = @"";
    }
    if (!mobile) {
        mobile = @"";
    }
    if (!province) {
        province = @"";
    }
    if (!city) {
        city = @"";
    }
    if (!district) {
        district = @"";
    }
    if (!street) {
        street = @"";
    }
    if (!details) {
        details = @"";
    }
    NSDictionary *params = @{
                             @"token":token,
                             @"displayName":displayName,
                             @"passport":passport,
                             @"military":military,
                             @"receiverName":receiverName,
                             @"mobile":mobile,
                             @"province":province,
                             @"city":city,
                             @"district":district,
                             @"street":street,
                             @"details":details
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/changeUserInformation" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)rebindMobileSedMSMcode:(NSString *)mobile token:(NSString *)token controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"token":token,
                             @"mobile":mobile  ,
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/sendVerifyMobile" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)saveRebindNewMobile:(NSString *)newMobile oldMobile:(NSString *)oldMobile token:(NSString *)token smsCode:(NSString *)smsCode controller:(NSObject *)controller success:(successBlock)success error:(failureBlock)failure {
    NSDictionary *params = @{
                             @"oldMobile":oldMobile,
                             @"newMobile":newMobile,
                             @"captcha":smsCode,
                             @"token":token
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/changeMobile" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)sendMailCode:(NSString *)email token:(NSString *)token controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                           @"token":token,
                           @"email":email
                           };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/sendVerifyEmail" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)saveEmailInfo:(NSString *)email token:(NSString *)token code:(NSString *)code controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"token":token,
                             @"email":email,
                             @"code":code,
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/bindemailSave" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)userResetPasswordWithOldPassWord:(NSString *)oldPassword newPassWord:(NSString *)newPassWord token:(NSString *)token controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"token":token,
                             @"oldPassword":oldPassword,
                             @"newPassword":newPassWord
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/changePassword" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    engine.requestSerializer = DDRequestSerializerHTTP;
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)findPwdImgcode:(NSObject *)controller Success:(successBlock)success failure:(failureBlock)failure{
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/findPwdImgcode" requestType:DDrequestTypePOST requestParams:nil success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)checkUserAccount:(NSString *)account imageCodeId:(NSString *)imageCodeID code:(NSString *)code controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"account":account,
                             @"imgcodeid":imageCodeID,
                             @"code":code,
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/findPwdUser" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)forgerPwdToSendSMScode:(NSString *)mobile controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"mobile":mobile
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/sendForgetMobile" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)forgetPwdRestPassword:(NSString *)password confirmPassword:(NSString *)confirmPassword smsCode:(NSString *)smsCode mobile:(NSString *)mobile controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"mobile":mobile,
                             @"captcha":smsCode,
                             @"passwd":password,
                             @"passwdConfirm":confirmPassword
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/mobileRestPassword" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)userLoginOutWithToken:(NSString *)token Controller:(NSObject *)controller success:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"token":token
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:controller BaseUrl:KUSERBASEURL requestUrl:@"/app_api/user/logout" requestType:DDrequestTypePOST requestParams:params success:success failure:failure];
    engine.isNeedAutoDealError = NO;
    return [self callRequestWithWorkEngnine:engine];
}

- (NSNumber *)uploadImage:(UIImage *)image success:(DDuploadSuccessBlcok)success faliure:(failureBlock)failure {
    DDuploadNetWorkEngine *engine = [DDuploadNetWorkEngine uploadengineWithImage:image baseUrl:KUSERBASEURL requestUrl:@"/img/add" progress:nil success:success failure:failure];
    return [self upLoadDataWithUploadWorkengine:engine];
}

- (NSNumber *)checkUpdateVersionSuccess:(successBlock)success failure:(failureBlock)failure {
    NSDictionary *params = @{
                             @"platform":@"2",
                             @"userVersion":@"1.1"
                             };
    DDnetWrokEngine *engine = [DDnetWrokEngine engineWithControl:nil BaseUrl:KUSERUPDATEBASEURL requestUrl:@"/verSetting/checkNewVersion" requestType:DDrequestTypeGET requestParams:params success:success failure:failure];
    engine.isNeedAutoDealError = NO;
    engine.requestSerializer = DDRequestSerializerHTTP;
    return  [self callRequestWithWorkEngnine:engine];
}

@end
